package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.bean.PoleSumBean;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.utils.DataUtil;
import com.hongxun.design.utils.httputil.HttpStringCodeTableUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/6.
 */
public class PoleSunAdapter extends BaseAdapter {
    Context context;
    List<PoleSumBean> poleSumBeans;
    LayoutInflater inflater;
    ArrayList<SystemTypeBean> type;
    public PoleSunAdapter(Context context, List<PoleSumBean> poleSumBeans) {
        this.context = context;
//        if (poleSumBeans.size()==0){
//            PoleSumBean bean=new PoleSumBean();
//            bean.setNumber("1#");
//            bean.setCodeset("D农修103-1220-D");
//            bean.setPole_type("分支杆");
//            bean.setPole_attribute("是");
//            poleSumBeans.add(bean);
//        }
        this.poleSumBeans = poleSumBeans;
        type= DataUtil.getSystemTypeBean(HttpStringCodeTableUtil.poleType);
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return poleSumBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return poleSumBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holldler holldler = null;
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_polesum, null);
            holldler = new Holldler(view);
            view.setTag(holldler);
        } else {
            holldler = (Holldler) view.getTag();
        }

        PoleSumBean bean;
        try {
            bean = poleSumBeans.get(i);
            holldler.number.setText(bean.getNumber());
            holldler.type.setText(getType(bean.getPole_type()));
            holldler.codeset.setText(bean.getCodeset());
            holldler.attribute.setText(getNew(bean.getPole_attribute()));
//            poleType

        } catch (Exception e) {
        }

        return view;
    }

    private String getType(String s){
        for (SystemTypeBean b:type){
            if (b.getTypecode().equals(s)){
                return b.getTypename();
            }
        }
        return "";
    }


    private String getNew(String s){
        if (s.equals("11")){
            return "新建";
        }else{
            return "利旧";
        }
    }
    class Holldler {
        TextView number, type, codeset, attribute;
        Holldler(View v) {
            number = (TextView) v.findViewById(R.id.polesum_number);
            type = (TextView) v.findViewById(R.id.polesum_pole_type);
            codeset = (TextView) v.findViewById(R.id.polesum_codeset);
            attribute = (TextView) v.findViewById(R.id.polesum_pole_attribute);
        }
    }

}
